package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ProductSpecController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 商品规格
 * @Author 孤妤
 * @Date: 2023/12/8 11:20
 */
@Tag(name = "商品规格")
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "商品规格列表分页")
    public Result<PageInfo<ProductSpec>> findProductSpecPage(@PathVariable Integer pageNum,
                                                             @PathVariable Integer pageSize){
        PageInfo<ProductSpec> pageInfo = productSpecService.findProductSpecPage(pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    @Operation(summary = "添加商品规格")
    public Result addProductSpec(@RequestBody ProductSpec productSpec){
        productSpecService.addProductSpec(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("添加成功");
    }
    @PutMapping("/updateById")
    @Operation(summary = "修改商品规格")
    public Result changeProductSpecById(@RequestBody ProductSpec productSpec){
         productSpecService.changeProductSpecById(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除商品规格")
    public Result removeProductSpecById(@PathVariable Long id){
        productSpecService.removeProductSpecById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }
    @GetMapping("/findAll")
    @Operation(summary = "查询所有商品规格")
    public Result<List<ProductSpec>> findAll(){
        List<ProductSpec> productSpecList = productSpecService.findAll();
        return Result.build(productSpecList,ResultCodeEnum.SUCCESS);
    }
}
